package work2;

import java.util.Scanner;

public class Quetion4 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		Complex x = new Complex(0, 0);
		Complex y = new Complex(0, 0);

		System.out.println("  ==== 简易复数计算器 ==== ");

		System.out.println("请输入第一个数的实部和虚部（用空格分隔）：");

		String[] temp = input.nextLine().split("\\s+");
		assert_exit(temp.length == 2, "Err: 输入有误。");

		x.Real = Double.parseDouble(temp[0]);
		x.I = Double.parseDouble(temp[1]);

		System.out.println("请输入第二个数的实部和虚部（用空格分隔）：");

		temp = input.nextLine().split("\\s+");
		assert_exit(temp.length == 2, "Err: 输入有误。");

		y.Real = Double.parseDouble(temp[0]);
		y.I = Double.parseDouble(temp[1]);

		input.close();

		System.out.println("运算结果如下：");
		System.out.printf("(%s)+(%s) = %s\n", x.ToString(), y.ToString(), Complex.Add(x, y).ToString());
		System.out.printf("(%s)-(%s) = %s\n", x.ToString(), y.ToString(), Complex.Sub(x, y).ToString());
		System.out.printf("(%s)*(%s) = %s\n", x.ToString(), y.ToString(), Complex.Mul(x, y).ToString());
		System.out.printf("(%s)/(%s) = %s\n", x.ToString(), y.ToString(), Complex.Div(x, y).ToString());

	}

	private static void assert_exit(boolean b, String errStr) {
		if (!b) {
			System.out.println(errStr);
			System.out.println("断言为假，程序中断运行。");
			System.exit(0);
		}
	}

	// private static void assert_exit(boolean b) {
	// if(!b){
	// System.out.println("断言为假，程序中断运行。");
	// System.exit(0);
	// }
	// }
}